<template>
  <div>
    <!-- 幻灯片、轮播图开始 -->
    <div v-swiper:mySwiper="swiperOption">
      <div class="swiper-wrapper">
        <div
          v-for="banner in banners"
          :key="banner.id"
          class="swiper-slide"
          style="background: #040B1B;"
        >
          <a target="_blank" :href="banner.linkUrl" :title="banner.title">
            <img :src="banner.imageUrl" :alt="banner.title" />
          </a>
        </div>
      </div>
      <div class="swiper-pagination swiper-pagination-white"></div>
      <div class="swiper-button-prev swiper-button-white" slot="button-prev"></div>
      <div class="swiper-button-next swiper-button-white" slot="button-next"></div>
    </div>
    <!-- 幻灯片、轮播图结束 -->

    <div id="aCoursesList">
      <!-- 课程开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">热门课程</span>
            </h2>
          </header>
          <div>
            <article class="comm-course-list">
              <ul class="of" id="bna">
                <li v-for="course in courses" :key="course.id">
                  <div class="cc-l-wrap">
                    <section class="course-img">
                      <img :src="course.cover" class="img-responsive" :alt="course.title" />
                      <div class="cc-mask">
                        <a href="/course/1" title="开始学习" class="comm-btn c-btn-1">开始学习</a><!-- 默认去找当前文件目录下的course目录下的index.vue -->
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a
                        href="/course/1"
                        :title="course.title"
                        class="course-title fsize18 c-333"
                      >{{ course.title }}</a>
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fr jgTag bg-green" v-if="Number(course.price) === 0.00">
                        <i class="c-fff fsize12 f-fA">免费</i>
                      </span>
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA">8354人学习</i>
                        |
                        <i class="c-999 f-fA">534评论</i>
                      </span>
                    </section>
                  </div>
                </li>
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="#" title="全部课程" class="comm-btn c-btn-2">全部课程</a>
            </section>
          </div>
        </section>
      </div>
      <!-- 课程结束 -->

      <!-- 讲师开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">名师大咖</span>
            </h2>
          </header>
          <div>
            <article class="i-teacher-list">
              <ul class="of">
                <li v-for="teacher in teachers" :key="teacher.id">
                  <section class="i-teach-wrap">
                    <div class="i-teach-pic">
                      <a href="/teacher/1" :title="teacher.name"><!-- 默认去找当前文件目录下的teacher目录下的index.vue -->
                        <img :alt="teacher.name" :src="teacher.avatar" />
                      </a>
                    </div>
                    <div class="mt10 hLh30 txtOf tac">
                      <a
                        href="/teacher/1"
                        :title="teacher.name"
                        class="fsize18 c-666"
                      >{{ teacher.name }}</a>
                    </div>
                    <div class="hLh30 txtOf tac">
                      <span class="fsize14 c-999">{{teacher.career}}</span>
                    </div>
                    <div class="mt15 i-q-txt">
                      <p class="c-999 f-fA">{{teacher.intro}}</p>
                    </div>
                  </section>
                </li>
              </ul>
              <div class="clear"></div>
            </article>
            <section class="tac pt20">
              <a href="#" title="全部讲师" class="comm-btn c-btn-2">全部讲师</a>
            </section>
          </div>
        </section>
      </div>
      <!-- 讲师结束 -->
    </div>
  </div>
</template>
<script>
import bannerApi from "@/api/banner/banner";
import indexApi from "@/api/index/index";
export default {
  data() {
    return {
      //swiper幻灯片、轮播图的前端组件
      swiperOption: {
        pagination: {
          el: ".swiper-pagination"
        },
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        }
      },
      //banner列表
      banners: [],
      //课程列表
      courses: [],
      //讲师列表
      teachers: []
    };
  },
  created() {
    this.getBanners();
    this.getHotCoursesAndTeachers();
  },
  methods: {
    //查询banner列表
    getBanners() {
      bannerApi.getBanners().then(response => {
        this.banners = response.data.data.list;
      });
    },
    //查询热门课程和讲师
    getHotCoursesAndTeachers() {
      indexApi.index().then(response => {
        this.courses = response.data.data.courseList;
        this.teachers = response.data.data.teacherList;
      });
    }
  }
};
</script>
